from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import DBUtils
import Buy
import CZ

class TestBuy:

    def test_buy1(self):
        CZ.cz5('伊拉克国民银行','1','1234567891548796','1','1000000','1')
        # li 用户id为 1
        Buy.buy1('lisi','123456',2,1,'666666','买入成功!','test_buy1')
        time.sleep(1)
        CZ.cz4('1234567891548796')


    def test_buy2(self):
        CZ.cz5('伊拉克国民银行', '1', '1234567891548796', '1', '1000000', '1')
        Buy.buy1('lisi', '123456', 2, 1, '666667', '买入失败!', 'test_buy2')
        time.sleep(1)
        CZ.cz4('1234567891548796')


    def test_buy3(self):
        CZ.cz5('伊拉克国民银行', '1', '1234567891548796', '14', '10', '1')
        # lisi4 用户id 为 14
        Buy.buy1('lisi4', '123456', 2, 1, '666666', '买入失败!，银行卡余额不足', 'test_buy3')
        time.sleep(1)
        CZ.cz4('1234567891548796')


    def test_buy4(self):

        Buy.buy1('lisi5','123456',2,1,'666666','买入失败!，请绑定银行卡','test_buy4')


    def test_buy5(self):
        CZ.cz5('伊拉克国民银行', '1', '1234567891548796', '1', '1000000', '1')

        driver = Buy.buy2('lisi', '123456', 2, 2, '666666')
        result = driver.find_element(By.XPATH, '//div[@class="jconfirm-content"]/div').text

        sql = 'select balance from bankcard where userId = 1 and defaultl = 1'
        data = DBUtils.select(sql,[])
        time.sleep(1)
        CZ.cz4('1234567891548796')

        if result == '买入成功!' and data[0][0] == 999900.00:
            print('通过')
        else:
            print('不通过！')
            driver.save_screenshot('test_buy5.png')

        assert result == '买入成功!' and data[0][0] == 999900.00

        driver.quit()


    def test_buy6(self):
        CZ.cz5('伊拉克国民银行', '1', '1234567891548796', '1', '1000000', '1')
        # 买入失败
        Buy.buy1('lisi', '123456', 2, 2, '666667', '买入失败!', 'test_buy6')
        time.sleep(1)
        CZ.cz4('1234567891548796')

    def test_buy7(self):

        CZ.cz5('伊拉克国民银行', '1', '1234567891548796', '14', '10', '1')
        # lisi4 id 为14
        Buy.buy1('lisi4', '123456', 2, 2, '666666', '买入失败!，银行卡余额不足', 'test_buy7')
        time.sleep(1)
        CZ.cz4('1234567891548796')


    def test_buy8(self):

        Buy.buy1('lisi5', '123456', 2, 2, '666666', '买入失败!，请绑定银行卡', 'test_buy8')



    def test_buy9(self):
        CZ.cz5('伊拉克国民银行', '1', '1234567891548796', '1', '1000000', '1')

        driver = Buy.buy2('lisi', '123456', 2, 3, '666666')

        result = driver.find_element(By.XPATH, '//div[@class="jconfirm-content"]/div').text

        sql = 'select balance from bankcard where userId = 1 and defaultl = 1'
        data = DBUtils.select(sql,[])

        time.sleep(1)
        CZ.cz4('1234567891548796')

        if result == '买入成功!' and data[0][0] == 999900.00:
            print('通过')
        else:
            print('不通过！')
            driver.save_screenshot('test_buy9.png')

        assert result == '买入成功!' and data[0][0] == 999900.00

        driver.quit()


    def test_buy10(self):
        CZ.cz5('伊拉克国民银行', '1', '1234567891548796', '1', '1000000', '1')
        Buy.buy1('lisi', '123456', 2, 3, '666667', '买入失败!', 'test_buy10')

        time.sleep(1)
        CZ.cz4('1234567891548796')


    def test_buy11(self):
        CZ.cz5('伊拉克国民银行', '1', '1234567891548796', '14', '10', '1')

        Buy.buy1('lisi4', '123456', 2, 3, '666666', '买入失败!，银行卡余额不足', 'test_buy11')

        time.sleep(1)
        CZ.cz4('1234567891548796')


    def test_buy12(self):

        Buy.buy1('lisi5', '123456', 2, 3, '666666', '买入失败!，请绑定银行卡', 'test_buy12')


    def test_buy13(self):

        # lisi6 用户id 82
        CZ.cz5('伊拉克国民银行', '1', '1234567891548796', '82', '10000000', '1')
        Buy.buy1('lisi6', '123456', 2, 3, '666667', '买入失败!,请前往个人信息设置支付密码', 'test_buy13')

        time.sleep(1)
        CZ.cz4('1234567891548796')

    def test_buy14(self):
        # lisi7 83
        CZ.cz5('伊拉克国民银行', '1', '1234567891548796', '83', '10000', '1')
        CZ.cz5('伊拉克国民银行', '1', '1234567891548797', '83', '10000', '0')
        CZ.cz5('伊拉克国民银行', '1', '1234567891548798', '83', '10000', '0')

        driver = Buy.buy2('lisi7', '123456', 2, 3, '666666')

        result = driver.find_element(By.XPATH, '//div[@class="jconfirm-content"]/div').text

        sql = 'select balance from bankcard where userId = 83 and defaultl = 1'
        data = DBUtils.select(sql, [])

        time.sleep(1)
        CZ.cz4('1234567891548796')
        CZ.cz4('1234567891548797')
        CZ.cz4('1234567891548798')


        if result == '买入成功!' and data[0][0] == 7000.00:
            print('通过')
        else:
            print('不通过！')

        assert result == '买入成功!' and data[0][0] == 7000.00

        driver.quit()


    def test_buy15(self):

        CZ.cz5('伊拉克国民银行', '1', '1234567891548796', '83', '10000', '1')
        CZ.cz5('伊拉克国民银行', '1', '1234567891548797', '83', '10000', '0')
        CZ.cz5('伊拉克国民银行', '1', '1234567891548798', '83', '10000', '0')

        driver = Buy.buy2('lisi7', '123456', 2, 3, '666666')

        result = driver.find_element(By.XPATH, '//div[@class="jconfirm-content"]/div').text

        sql = 'select balance from bankcard where userId = 83 and defaultl = 1'
        data = DBUtils.select(sql, [])

        time.sleep(1)
        CZ.cz4('1234567891548796')
        CZ.cz4('1234567891548797')
        CZ.cz4('1234567891548798')

        if result == '买入成功!' and data[0][0] == 7000.00:
            print('通过')
        else:
            print('不通过！')

        assert result == '买入成功!' and data[0][0] == 7000.00

        driver.quit()


    def test_buy16(self):

        Buy.buy1('lisi5', '123456', 2, 3, '666666', '买入失败!，请绑定银行卡', 'test_buy12')
